﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;
using KPIS.GERP.GFMS.APP.App_UI.Commons;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;

namespace KPIS.GERP.GFMS.APP.App_UI.UserControls
{
    public partial class DDL_BgmOption : System.Web.UI.UserControl
    {
        public RadComboBox ChildDLL;
        int nOffset = 10;
        Main main = new Main();
        IBLL_BGM_MAS_Option opt = new B_BGM_MAS_Option();

        //========param==========
        //Nullable<int> _nWidth;
        //Nullable<int> _nSetOffset;
        bool _bAll;
        string _strJobsiteSeq;

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public void LoadControl(Nullable<int> nWidth, Nullable<int> nSetOffset, bool bAll
            , string strJobsiteSeq)
        {
            if (nWidth != null)
                ddlBgmOptionSeq.Width = Unit.Pixel(nWidth.Value);

            if (nSetOffset != null)
                nOffset = nSetOffset.Value;

            _bAll = bAll;
            _strJobsiteSeq = strJobsiteSeq;
            LoadData();
        }

        public RadComboBox GetComboBox()
        {
            RadComboBox ddl = ddlBgmOptionSeq;
            return ddl;
        }

        private void LoadData()
        {
            ddlBgmOptionSeq.DataSource = opt.GetIntegrateProjectList(_strJobsiteSeq);
            ddlBgmOptionSeq.DataBind();

            if (_bAll)
            {
                main.InsertEmptyDDLAll(ddlBgmOptionSeq);
            }
            else
            {
                main.InsertEmptyDDLSelect(ddlBgmOptionSeq);
            }

            if (ChildDLL != null)
            {
                ddlBgmOptionSeq.AutoPostBack = true;
            }
        }

        public void SetSelectedValue(string strValue)
        {
            ddlBgmOptionSeq.SelectedValue = strValue;
            ddlBgmOptionSeq_SelectedIndexChanged(null, null);
        }

        protected void ddlBgmOptionSeq_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (ChildDLL != null)
            {
            }
        }

        //public string GetSelectedValue()
        //{
        //    string strValue = lblMoneyReqSeq.Text;

        //    return strValue;
        //}

        //protected void ddlMoneyReqSeq_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        //{
        //    string strMoneyReqSeq = ddlMoneyReqSeq.SelectedValue;
        //    lblMoneyReqSeq.Text = strMoneyReqSeq;

        //    if (Child != null)
        //    {

        //    }

        //    switch (Page.ToString())
        //    {
        //        case "ASP.app_ui_forms_fim_receives_aspx" :
        //            RadioButton rbContact2 = (RadioButton)Parent.FindControl("rbContact2");
        //            RadioButton rbEmp2 = (RadioButton)Parent.FindControl("rbEmp2");
        //            RadioButton rbTemp2 = (RadioButton)Parent.FindControl("rbTemp2");
        //            Label lblContactSeq = (Label)Parent.FindControl("lblContactSeq");
        //            Label lblEmpSeq = (Label)Parent.FindControl("lblEmpSeq");
        //            Label lblContactPersonSeq = (Label)Parent.FindControl("lblContactPersonSeq");
        //            Label lblContactName = (Label)Parent.FindControl("lblContactName");
        //            Label lblEmpName = (Label)Parent.FindControl("lblEmpName");
        //            Label lblContactPersonName = (Label)Parent.FindControl("lblContactPersonName");

        //            if (ddlMoneyReqSeq.SelectedValue.Length > 0)
        //            {
        //                M_FIM_MoneyRequests info = mr.GetInfo(ddlMoneyReqSeq.SelectedValue);

        //                if (info.debtor_contact_seq.ToString().Length > 0)
        //                {
        //                    rbContact2.Checked = false;
        //                    rbEmp2.Checked = false;
        //                    rbTemp2.Checked = true;
        //                    lblContactPersonSeq.Text = info.debtor_contact_seq.ToString();
        //                    lblContactPersonName.Text = info.debtor_contact_name;
        //                }
        //                else if (info.contact_seq.ToString().Length > 0)
        //                {
        //                    rbContact2.Checked = true;
        //                    rbEmp2.Checked = false;
        //                    rbTemp2.Checked = false;
        //                    lblContactSeq.Text = info.contact_seq.ToString();
        //                    lblContactName.Text = info.contact_name;
        //                }
        //                else
        //                {
        //                    rbContact2.Checked = false;
        //                    rbEmp2.Checked = true;
        //                    rbTemp2.Checked = false;
        //                    lblEmpSeq.Text = info.emp_seq.ToString();
        //                    lblEmpName.Text = info.emp_name;
        //                }
        //            }
        //            else
        //            {
        //                lblContactSeq.Text = "";
        //                lblEmpSeq.Text = "";
        //                lblContactPersonSeq.Text = "";
        //                lblContactName.Text = "";
        //                lblEmpName.Text = "";
        //                lblContactPersonName.Text = "";
        //            }
        //            break;

        //        case "ASP.app_ui_forms_fim_payments_aspx":
        //            Label lblPetitionName = (Label)Parent.FindControl("lblPetitionName");
        //            Label lblPetitionSeq = (Label)Parent.FindControl("lblPetitionSeq");
        //            Label lblPetitionDtlsSeq = (Label)Parent.FindControl("lblPetitionDtlsSeq");
        //            Label lblEventSeq = (Label)Parent.FindControl("lblEventSeq");
        //            Label lblBathAmount = (Label)Parent.FindControl("lblBathAmount");
        //            Label lblPayName = (Label)Parent.FindControl("lblPayName");
        //            Label lblPayee = (Label)Parent.FindControl("lblPayee");
        //            Label lblEmpSeq2 = (Label)Parent.FindControl("lblEmpSeq");
        //            Label lblContactSeq2 = (Label)Parent.FindControl("lblContactSeq");
        //            Label lblContactPersonSeq2 = (Label)Parent.FindControl("lblContactPersonSeq");

        //            if (ddlMoneyReqSeq.SelectedValue.Length > 0)
        //            {
        //                M_FIM_MoneyRequests info = mr.GetInfo(ddlMoneyReqSeq.SelectedValue);
        //                lblPetitionName.Text = info.petition_type_name;
        //                lblPetitionSeq.Text = info.petition_seq.ToString();
        //                lblPetitionDtlsSeq.Text = info.petition_dtls_seq.ToString();
        //                lblEventSeq.Text = info.event_seq.ToString();
        //                lblBathAmount.Text = info.total_amount_real.ToString();
        //                lblPayName.Text = "จ่ายเงิน" + " (" + info.money_req_name + ")";
        //                lblPayee.Text = info.payee_name;
        //                lblEmpSeq2.Text = info.emp_seq.ToString();
        //                lblContactSeq2.Text = info.contact_seq.ToString();
        //                lblContactPersonSeq2.Text = info.debtor_contact_seq.ToString();
        //            }
        //            else
        //            {
        //                lblPetitionName.Text = "";
        //                lblPetitionSeq.Text = "";
        //                lblPetitionDtlsSeq.Text = "";
        //                lblEventSeq.Text = "";
        //                lblBathAmount.Text = "0";
        //                lblPayName.Text = "";
        //                lblPayee.Text = "";
        //                lblEmpSeq2.Text = "";
        //                lblContactSeq2.Text = "";
        //                lblContactPersonSeq2.Text = "";
        //            }
        //            break;

        //        case "ASP.app_ui_forms_fim_moneyreturns_aspx":
                    
        //            RadGrid RadGrid2 = (RadGrid)Parent.FindControl("RadGrid2");
        //            Label lblDebtor = (Label)Parent.FindControl("lblEmpName");
        //            Label lblReturnSeq = (Label)Parent.FindControl("lblReturnSeq");
        //            IBLL_FIM_MoneyReturnDtls red = new B_FIM_MoneyReturnDtls();
        //            RadGrid2.DataSource = red.GetMoneyReqDtls(lblReturnSeq.Text, strMoneyReqSeq);
        //            RadGrid2.DataBind();
        //            lblDebtor.Text = mr.GetInfo(strMoneyReqSeq).payee_name;
        //            break;
        //    }
        //}

        //protected void ddlMoneyReqSeq_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        //{
        //    LoadData(e);
        //}
    }
}